<!--

    Copyright (C) 2015 The Gravitee team (http://gravitee.io)

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

            http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

-->
<mat-card>
  <mat-card-content>
    <div class="response-templates-list__header">
      <span>Define your own response templates if you're looking for overriding default responses from the gateway.</span>

      <ng-container *ngIf="!isReadOnly && responseTemplateTableData">
        <button *gioPermission="{ anyOf: ['api-response_templates-c'] }" mat-raised-button type="button" routerLink="./new" color="primary">
          <mat-icon svgIcon="gio:plus"></mat-icon> Add new Response Template
        </button>
      </ng-container>
    </div>

    <table
      mat-table
      [dataSource]="responseTemplateTableData"
      class="response-templates-list__table"
      id="responseTemplateTable"
      aria-label="Response Template table"
    >
      <!-- Key Column -->
      <ng-container matColumnDef="key">
        <th mat-header-cell *matHeaderCellDef id="key" width="25%">Key</th>
        <td mat-cell *matCellDef="let element">
          {{ element.key }}
        </td>
      </ng-container>
      <!-- Content-Type Column -->
      <ng-container matColumnDef="contentType">
        <th mat-header-cell *matHeaderCellDef id="contentType" width="25%">Content-Type</th>
        <td mat-cell *matCellDef="let element">
          {{ element.contentType }}
        </td>
      </ng-container>
      <!-- Status Code Column -->
      <ng-container matColumnDef="statusCode">
        <th mat-header-cell *matHeaderCellDef id="statusCode" width="25%">Status Code</th>
        <td mat-cell *matCellDef="let element">
          {{ element.statusCode }}
        </td>
      </ng-container>
      <!-- Actions Column -->
      <ng-container matColumnDef="actions">
        <th mat-header-cell *matHeaderCellDef id="actions" width="1%"></th>
        <td mat-cell *matCellDef="let element">
          <div class="response-templates-list__table__actions">
            <button
              *ngIf="isReadOnly"
              [routerLink]="['./', element.id]"
              mat-icon-button
              aria-label="Button to open Response Template detail"
            >
              <mat-icon svgIcon="gio:eye-empty"></mat-icon>
            </button>
            <button *ngIf="!isReadOnly" [routerLink]="['./', element.id]" mat-icon-button aria-label="Button to edit a Response Template">
              <mat-icon svgIcon="gio:edit-pencil"></mat-icon>
            </button>
            <ng-container *ngIf="!isReadOnly">
              <button
                *gioPermission="{ anyOf: ['api-response_templates-d'] }"
                (click)="onDeleteResponseTemplateClicked(element)"
                mat-icon-button
                aria-label="Button to delete a Response Template"
              >
                <mat-icon svgIcon="gio:trash"></mat-icon>
              </button>
            </ng-container>
          </div>
        </td>
      </ng-container>

      <tr mat-header-row *matHeaderRowDef="responseTemplateTableDisplayedColumns"></tr>
      <tr mat-row *matRowDef="let row; columns: responseTemplateTableDisplayedColumns"></tr>

      <!-- Row shown when there is no data -->
      <tr class="mat-mdc-row mdc-data-table__row" *matNoDataRow>
        <td class="mat-mdc-cell mdc-data-table__cell" [attr.colspan]="responseTemplateTableDisplayedColumns.length">
          No Response Templates
        </td>
      </tr>
    </table>
  </mat-card-content>
</mat-card>
